<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="班次名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入班次名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="班次状态"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="保存时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="创建人" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建人名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增
        </el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handleDelete"
        >删除
        </el-button>
      </el-col>


      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="timeShiftList" @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{ (pageNum - 1) * pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="班次名称" prop="name" :show-overflow-tooltip="true" width="100"/>
      <el-table-column label="打卡次数" prop="typeName" width="150"/>
      <el-table-column label="上下班时间" prop="showDateTime" width="200"/>
      <el-table-column label="创建人" prop="createBy" :show-overflow-tooltip="true" width="120"/>
      <el-table-column label="保存时间" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" width="100">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status"
            :active-value="0"
            :inactive-value="1"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>


      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >编辑
          </el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >详情
          </el-button>

        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 10"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :page-sizes="[10]"
      @pagination="getList"
    />
    <!-- 添加或修改班次对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <span style="font-weight:bold">基本信息</span>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="班次名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入班次名称" style="width: 180px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in statusOptions"
                  :key="dict.label"
                  :label="dict.value"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <span>
         <span style="font-weight:bold">打卡时段设置</span>
          <span>（该班次为一天上下班打卡次数）</span>
        </span>

        <el-divider></el-divider>
        <el-row>
          <el-tag type="info" :color="color0" @click="changTag(0)">休息不打卡</el-tag>
          <el-tag type="info" :color="color1" @click="changTag(1)">一天1次上下班打卡</el-tag>
          <el-tag type="info" :color="color2" @click="changTag(2)">一天2次上下班打卡</el-tag>
          <el-tag type="info" :color="color3" @click="changTag(3)">一天3次上下班打卡</el-tag>
          <el-tag type="info" :color="color4" @click="changTag(4)">一天4次上下班打卡</el-tag>
        </el-row>

        <el-row style="margin-top: 15px">
          <el-col :span="12">
            <span width="60px">上下班时间</span>
          </el-col>
        </el-row>


        <el-row style="margin-top: 15px">
          <el-col :span="12">
            <el-form-item label="第1次 上班" prop="firstBeginTime" v-show="showTime1">
              <el-time-select
                v-model="form.firstBeginTime"

                :picker-options="{
             start: '00:00',
              step: '00:15',
              end: '23:59'
            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="form.firstBeginChecked" style="margin-left: 8px">次日</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="第1次 下班" prop="firstEndTime" v-show="showTime1">
              <el-time-select
                v-model="form.firstEndTime"
                :picker-options="{
                  start: '00:00',
                  step: '00:15',
                  end: '23:59'

            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="form.firstEndChecked" style="margin-left: 8px">次日</el-checkbox>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="第2次 上班" prop="secondBeginTime" v-show="showTime2">
              <el-time-select
                v-model="form.secondBeginTime"

                :picker-options="{
                 start: '00:00',
                step: '00:15',
                end: '23:59'

            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="form.secondBeginChecked" style="margin-left: 8px">次日</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="第2次 下班" prop="secondEndTime" v-show="showTime2">
              <el-time-select
                v-model="form.secondEndTime"
                :picker-options="{
                   start: '00:00',
                    step: '00:15',
                    end: '23:59'

            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="form.secondEndChecked" style="margin-left: 8px">次日</el-checkbox>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="第3次 上班" prop="threeBeginTime" v-show="showTime3">
              <el-time-select
                v-model="form.threeBeginTime"
                :picker-options="{
                  start: '00:00',
                  step: '00:15',
                  end: '23:59'

            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="form.threeBeginChecked" style="margin-left: 8px">次日</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="第3次 下班" prop="threeEndTime" v-show="showTime3">
              <el-time-select
                v-model="form.threeEndTime"
                :picker-options="{
                 start: '00:00',
                  step: '00:15',
                  end: '23:59'

            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="form.threeEndChecked" style="margin-left: 8px">次日</el-checkbox>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="第4次 上班" prop="fourBeginTime" v-show="showTime4">
              <el-time-select
                v-model="form.fourBeginTime"
                :picker-options="{
                start: '00:00',
                step: '00:15',
                end: '23:59'


            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="form.fourBeginChecked" style="margin-left: 8px">次日</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="第4次 下班" prop="fourEndTime" v-show="showTime4">
              <el-time-select
                v-model="form.fourEndTime"
                :picker-options="{
                start: '00:00',
                step: '00:15',
               end: '23:59'
            }"
                placeholder=" ">
              </el-time-select>
              <el-checkbox v-model="form.fourEndChecked" style="margin-left: 8px">次日</el-checkbox>
            </el-form-item>
          </el-col>

        </el-row>

        <span>
         <span style="font-weight:bold">其他设置</span>

        </span>
        <el-divider></el-divider>
        <div v-show="showDiv">
        <el-row>
          1、迟到状态标准：晚于上班打卡
          <el-input
            v-model="form.late"
            placeholder=" "
            size="small"
            style="width: 60px"
          />
          分钟内计为迟到；晚于上班打卡

          <el-input
            v-model="form.generallyLate"
            placeholder=" "
            size="small"
            style="width: 60px"
          />
          分钟内计为一般迟到；晚于上班打卡
          <el-input
            v-model="form.seriouslyLate"
            placeholder=" "

            size="small"
            style="width: 60px"
          />
          分钟内计为严重迟到；

        </el-row>
        <el-row>
          2、早退状态标准：早于下班打卡
          <el-input
            v-model="form.leaveEarly"
            placeholder=""
            size="small"
            style="width: 60px"
          />
          分钟内计为早退；
        </el-row>
        <el-row>
          3、旷工状态标准：迟到超过
          <el-input
            v-model="form.absenteeism"
            placeholder=" "
            size="small"
            style="width: 60px"
          />
          分钟计为该班次旷工，超过早退时间也为该班次旷工；
        </el-row>
        </div>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 添加或修改班次对话框 -->
    <el-dialog :title="title" :visible.sync="openView" width="780px" append-to-body>
      <el-form ref="formView" :model="formView" label-width="80px">
        <span style="font-weight:bold">基本信息</span>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="班次名称" prop="name">
              <el-input v-model="formView.name" placeholder="请输入班次名称" disabled style="width: 180px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="formView.status" disabled>
                <el-radio
                  v-for="dict in statusOptions"
                  :key="dict.label"
                  :label="dict.value"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <span>
         <span style="font-weight:bold">打卡时段设置</span>
          <span>（该班次为一天上下班打卡次数）</span>
        </span>

        <el-divider></el-divider>
        <el-row>
          <el-tag type="info" :color="color0" @click="changTag(0)">休息不打卡</el-tag>
          <el-tag type="info" :color="color1" @click="changTag(1)">一天1次上下班打卡</el-tag>
          <el-tag type="info" :color="color2" @click="changTag(2)">一天2次上下班打卡</el-tag>
          <el-tag type="info" :color="color3" @click="changTag(3)">一天3次上下班打卡</el-tag>
          <el-tag type="info" :color="color4" @click="changTag(4)">一天4次上下班打卡</el-tag>
        </el-row>

        <el-row style="margin-top: 15px">
          <el-col :span="12">
            <span width="60px">上下班时间</span>
          </el-col>
        </el-row>


        <el-row style="margin-top: 15px">
          <el-col :span="12">
            <el-form-item label="第1次 上班" prop="firstBeginTime" v-show="showTime1">
              <el-time-select
                v-model="formView.firstBeginTime"
                disabled
                :picker-options="{
             start: '00:00',
              step: '00:15',
              end: '23:59'
            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="formView.firstBeginChecked" style="margin-left: 8px" disabled>次日</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="第1次 下班" prop="firstEndTime" v-show="showTime1">
              <el-time-select
                v-model="formView.firstEndTime"
                disabled
                :picker-options="{
                  start: '00:00',
                  step: '00:15',
                  end: '23:59',

            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="formView.firstEndChecked" style="margin-left: 8px" disabled>次日</el-checkbox>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="第2次 上班" prop="secondBeginTime" v-show="showTime2" disabled>
              <el-time-select
                v-model="formView.secondBeginTime"
                disabled
                :picker-options="{
                 start: '00:00',
                step: '00:15',
                end: '23:59',

            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="formView.secondBeginChecked" style="margin-left: 8px" disabled>次日</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="第2次 下班" prop="secondEndTime" v-show="showTime2" disabled>
              <el-time-select
                v-model="formView.secondEndTime"
                disabled
                :picker-options="{
                   start: '00:00',
                    step: '00:15',
                    end: '23:59',

            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="formView.secondEndChecked" style="margin-left: 8px" disabled>次日</el-checkbox>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="第3次 上班" prop="threeBeginTime" v-show="showTime3">
              <el-time-select
                disabled
                v-model="formView.threeBeginTime"
                :picker-options="{
                  start: '00:00',
                  step: '00:15',
                  end: '23:59',

            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="formView.threeBeginChecked" style="margin-left: 8px" disabled>次日</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="第3次 下班" prop="threeEndTime" v-show="showTime3">
              <el-time-select
                v-model="formView.threeEndTime"
                disabled
                :picker-options="{
                 start: '00:00',
                  step: '00:15',
                  end: '23:59',

            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="formView.threeEndChecked" style="margin-left: 8px" disabled>次日</el-checkbox>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="第4次 上班" prop="fourBeginTime" v-show="showTime4">
              <el-time-select
                v-model="formView.fourBeginTime"
                disabled
                :picker-options="{
                start: '00:00',
                step: '00:15',
                end: '23:59',


            }"
                placeholder="">
              </el-time-select>
              <el-checkbox v-model="formView.fourBeginChecked" style="margin-left: 8px" disabled>次日</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="第4次 下班" prop="fourEndTime" v-show="showTime4" disabled>
              <el-time-select
                v-model="formView.fourEndTime"
                disabled
                :picker-options="{
                start: '00:00',
                step: '00:15',
               end: '23:59',

            }"
                placeholder=" ">
              </el-time-select>
              <el-checkbox v-model="formView.fourEndChecked" style="margin-left: 8px" disabled>次日</el-checkbox>
            </el-form-item>
          </el-col>

        </el-row>

        <span>
         <span style="font-weight:bold">其他设置</span>

        </span>
        <el-divider></el-divider>
        <div v-show="showDiv">


        <el-row>
          1、迟到状态标准：晚于上班打卡
          <el-input
            v-model="formView.late"
            placeholder=" "
            size="small"
            disabled
            style="width: 60px"
          />
          分钟内计为普通迟到；晚于上班打卡

          <el-input
            v-model="formView.generallyLate"
            placeholder=" "
            size="small"
            disabled
            style="width: 60px"
          />
          分钟内计为一般迟到；晚于上班打卡
          <el-input
            v-model="formView.seriouslyLate"
            placeholder=" "
            disabled
            size="small"
            style="width: 60px"
          />
          分钟内计为严重迟到；

        </el-row>
        <el-row>
          2、早退状态标准：早于下班打卡
          <el-input
            v-model="formView.leaveEarly"
            placeholder=""
            disabled
            size="small"
            style="width: 60px"
          />
          分钟内计为早退；
        </el-row>
        <el-row>
          3、旷工状态标准：迟到超过
          <el-input
            v-model="formView.absenteeism"
            placeholder=" "
            size="small"
            disabled
            style="width: 60px"
          />
          分钟计为该班次旷工，超过早退时间也为该班次旷工；
        </el-row>

        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">

        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


  </div>

</template>

<script>

import {getToken} from "@/utils/auth";
import {
  listTermTimeShift,
  add,
  getTermTimeShift,
  delTermTimeShift,
  update,
  modifTermTimeShiftStatus
} from '@/api/job/termTimeShift/termTimeShift'

export default {
  name: "index",

  data() {
    return {
      show: false,
      type: 4,
      showEdit: [],
      needNumber: 0,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      ids: [],
      statusArray: [],
      flag: false,
      loading: true,
      // 总条数
      total: 0,
      pageNum: 1,
      pageSize: 10,
      // 显示搜索条件
      showSearch: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      openView: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        createBy: undefined,
        status: undefined
      },
      // 表单参数
      form: {status: 1},
      formView: {},
      priceFormOpen: false,
      priceForm: {
        // 是否显示弹出层（用户导入）
        // 弹出层标题（用户导入）
        title: "修改价格",
      },
      color0:'',
      color1: '',
      color2: '',
      color3: '',
      color4: '#000000',
      showTime1: true,
      showTime2: true,
      showTime3: true,
      showTime4: true,
      showDiv:true,
      timeShiftList: [],
      statusOptions: [{value: 0, label: '启用'}, {value: 1, label: '停用'}],
      rules: {
        name: [
          {required: true, message: "班次名称不能为空", trigger: "blur"},
          {min: 2, max: 20, message: '班次名称长度必须介于 2 和 20 之间', trigger: 'blur'}
        ],
        status: [
          {required: true, message: "状态不能空"}
        ],
        late: [
          {required: true, type: 'number', message: "迟到不能为空且需为数字", trigger: "blur", transform: (value) => Number(value)}
        ],
        generallyLate: [
          {
            required: true,
            type: 'number',
            message: "一般迟到不能为空且需为数字",
            trigger: "blur",
            transform: (value) => Number(value)
          }
        ],
        seriouslyLate: [
          {
            required: true,
            type: 'number',
            message: "严重迟到不能为空且需为数字",
            trigger: "blur",
            transform: (value) => Number(value)
          }
        ],
        leaveEarly: [
          {required: true, type: 'number', message: "早退不能为空且需为数字", trigger: "blur", transform: (value) => Number(value)}
        ],
        absenteeism: [
          {required: true, type: 'number', message: "旷工不能为空且需为数字", trigger: "blur", transform: (value) => Number(value)}
        ],
      }
    }
  },
  created() {
    this.getList();
  },
  methods: {


    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.statusArray = selection.map(item => item.status)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.openView = false;
      this.reset();
    },
    priceFormCancel() {
      this.priceFormOpen = false;
    },
// 表单重置
    reset() {
      this.form = {
        id: undefined,
        name: undefined,
        type: undefined,
        status: undefined,
        firstBeginChecked: false,
        firstEndChecked: false,
        secondBeginChecked: false,
        secondEndChecked: false,
        threeBeginChecked: false,
        threeEndChecked: false,
        fourBeginChecked: false,
        fourEndChecked: false,

      };
      this.resetForm("form");
    },
    /** 查询列表 */
    getList() {
      this.loading = true;

      listTermTimeShift(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
          this.timeShiftList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    handleStatusChange(row) {
      let text = row.status == "0" ? "启用" : "停用";

      this.$confirm('确认要' + text + row.name + '"班次吗?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        let data = {id: row.id, status: row.status};
        return modifTermTimeShiftStatus(data);
      }).then(() => {
        this.msgSuccess(text + "成功");
      }).catch(function () {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id || this.ids;
      const status = row.status || this.statusArray;
      if (id == '') {
        this.$alert("请先选中记录后再删除！", "错误提示", {dangerouslyUseHTMLString: true});
        return;
      }
      if (this.statusArray.length > 0) {
        for (var i = 0; i < status.length; i++) {
          if (status[i] == 0) {
            this.$alert("有启用状态不能删除！", "错误提示", {dangerouslyUseHTMLString: true});
            return;
          }
        }

      } else if (row.status == 0) {
        this.$alert("有启用状态不能删除！", "错误提示", {dangerouslyUseHTMLString: true});
        return;
      }
      this.$confirm('是否确认删除编号为"' + id + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delTermTimeShift(id);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 提交按钮 */
    submitForm: function () {

      if (this.type == 1) {
        if (this.form.firstBeginTime == null || this.form.firstEndTime == null) {
          this.$alert("第一次上下班打卡中有空值，请核对", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
      } else if (this.type == 2) {

        if (this.form.firstBeginTime == null || this.form.firstEndTime == null) {
          this.$alert("第一次上下班打卡中有空值，请核对", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
        if (this.form.secondBeginTime == null || this.form.secondEndTime == null) {
          this.$alert("第二次上下班打卡中有空值，请核对", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
      } else if (this.type == 3) {

        if (this.form.firstBeginTime == null || this.form.firstEndTime == null) {
          this.$alert("第一次上下班打卡中有空值，请核对", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
        if (this.form.secondBeginTime == null || this.form.secondEndTime == null) {
          this.$alert("第二次上下班打卡中有空值，请核对", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
        if (this.form.threeBeginTime == null || this.form.threeEndTime == null) {
          this.$alert("第三次上下班打卡中有空值，请核对", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
      } else if (this.type == 4) {

        if (this.form.firstBeginTime == null || this.form.firstEndTime == null) {
          this.$alert("第一次上下班打卡中有空值，请核对", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
        if (this.form.secondBeginTime == null || this.form.secondEndTime == null) {
          this.$alert("第二次上下班打卡中有空值，请核对", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
        if (this.form.threeBeginTime == null || this.form.threeEndTime == null) {
          this.$alert("第三次上下班打卡中有空值，请核对", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
        if (this.form.fourBeginTime == null || this.form.fourEndTime == null) {
          this.$alert("第四次上下班打卡中有空值，请核对", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
      }
      if (this.type > 0) {
        if (!Number(this.form.late) || Number(this.form.late) < 0) {
          this.$alert("迟到时间值为数字且大于0", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
        if (!Number(this.form.generallyLate) || Number(this.form.generallyLate) < 0) {
          this.$alert("一般迟到时间值为数字且大于0", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
        if (!Number(this.form.seriouslyLate) || Number(this.form.seriouslyLate) < 0) {
          this.$alert("严重迟到时间值为数字且大于0", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
        if (!Number(this.form.leaveEarly) || Number(this.form.leaveEarly) < 0) {
          this.$alert("早退时间值为数字且大于0", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }
        if (!Number(this.form.absenteeism) || Number(this.form.absenteeism) < 0) {
          this.$alert("旷工时间值为数字且大于0", "错误提示", {dangerouslyUseHTMLString: true});
          return;
        }


      }
      if (this.form.firstBeginChecked) {
        this.form.firstBeginChecked = 1;
      } else {
        this.form.firstBeginChecked = 0;
      }
      if (this.form.firstEndChecked) {
        this.form.firstEndChecked = 1;
      } else {
        this.form.firstEndChecked = 0;
      }
      if (this.form.secondBeginChecked) {
        this.form.secondBeginChecked = 1;
      } else {
        this.form.secondBeginChecked = 0;
      }
      if (this.form.secondEndChecked) {
        this.form.secondEndChecked = 1;
      } else {
        this.form.secondEndChecked = 0;
      }
      if (this.form.threeBeginChecked) {
        this.form.threeBeginChecked = 1;
      } else {
        this.form.threeBeginChecked = 0;
      }
      if (this.form.threeEndChecked) {
        this.form.threeEndChecked = 1;
      } else {
        this.form.threeEndChecked = 0;
      }
      if (this.form.fourBeginChecked) {
        this.form.fourBeginChecked = 1;
      } else {
        this.form.fourBeginChecked = 0;
      }
      if (this.form.fourEndChecked) {
        this.form.fourEndChecked = 1;
      } else {
        this.form.fourEndChecked = 0;
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.type = this.type;

          if (this.form.id != undefined) {
            update(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            add(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      if (row.status == 0) {
        this.$alert("启用状态不能修改！", "错误提示", {dangerouslyUseHTMLString: true});
        return;
      }
      getTermTimeShift(id).then(response => {
        this.form = response.data;
        if (this.form.firstBeginChecked == 1) {
          this.form.firstBeginChecked = true;
        }
        if (this.form.firstEndChecked == 1) {
          this.form.firstEndChecked = true;
        }
        if (this.form.secondBeginChecked == 1) {
          this.form.secondBeginChecked = true;
        }
        if (this.form.secondEndChecked) {
          this.form.secondEndChecked = true;
        }
        if (this.form.threeBeginChecked) {
          this.form.threeBeginChecked = true;
        }
        if (this.form.threeEndChecked) {
          this.form.threeEndChecked = true;
        }
        if (this.form.fourBeginChecked) {
          this.form.fourBeginChecked = true;
        }
        if (this.form.fourEndChecked) {
          this.form.fourEndChecked = true;
        }
        this.changTag(this.form.type);
        this.open = true;
        this.title = "班次信息";
      });
    },

    handleView(row) {
      this.reset();
      const id = row.id || this.ids
      getTermTimeShift(id).then(response => {
        this.formView = response.data;
        if (this.formView.firstBeginChecked == 1) {
          this.formView.firstBeginChecked = true;
        }
        if (this.formView.firstEndChecked == 1) {
          this.formView.firstEndChecked = true;
        }
        if (this.formView.secondBeginChecked == 1) {
          this.formView.secondBeginChecked = true;
        }
        if (this.formView.secondEndChecked) {
          this.formView.secondEndChecked = true;
        }
        if (this.formView.threeBeginChecked) {
          this.formView.threeBeginChecked = true;
        }
        if (this.formView.threeEndChecked) {
          this.formView.threeEndChecked = true;
        }
        if (this.formView.fourBeginChecked) {
          this.formView.fourBeginChecked = true;
        }
        if (this.formView.fourEndChecked) {
          this.formView.fourEndChecked = true;
        }
        this.changTag(this.formView.type);
        this.openView = true;
        this.title = "班次信息";
      });
    },
    changTag(value) {
      if (value == 0) {
        this.color0 = "#000000";
        this.color1 = "0";
        this.color2 = "";
        this.color3 = "";
        this.color4 = "";
        this.showDiv = false;
        this.showTime1 = false;
        this.showTime2 = false;
        this.showTime3 = false;
        this.showTime4 = false;
        this.form.secondBeginTime = '';
        this.form.secondEndTime = '';
        this.form.threeBeginTime = '';
        this.form.threeEndTime = '';
        this.form.fourBeginTime = '';
        this.form.fourEndTime = '';
        this.type = 0;
      } else if (value == 1) {
        this.color0 = "";
        this.color1 = "#000000";
        this.color2 = "";
        this.color3 = "";
        this.color4 = "";
        this.showDiv = true;
        this.showTime1 = true;
        this.showTime2 = false;
        this.showTime3 = false;
        this.showTime4 = false;
        this.form.secondBeginTime = '';
        this.form.secondEndTime = '';
        this.form.threeBeginTime = '';
        this.form.threeEndTime = '';
        this.form.fourBeginTime = '';
        this.form.fourEndTime = '';
        this.type = 1;
      } else if (value == 2) {
        this.color0 = "";
        this.color2 = "#000000";
        this.color1 = "";
        this.color3 = "";
        this.color4 = "";
        this.showTime1 = true;
        this.showTime2 = true;
        this.showTime3 = false;
        this.showTime4 = false;
        this.form.threeBeginTime = '';
        this.form.threeEndTime = '';
        this.form.fourBeginTime = '';
        this.form.fourEndTime = '';
        this.type = 2;
      } else if (value == 3) {
        this.color0 = "";
        this.color3 = "#000000";
        this.color2 = "";
        this.color1 = "";
        this.color4 = "";
        this.showDiv = true;
        this.showTime1 = true;
        this.showTime2 = true;
        this.showTime3 = true;
        this.showTime4 = false;

        this.form.fourBeginTime = '';
        this.form.fourEndTime = '';
        this.type = 3;
      } else if (value == 4) {
        this.color0 = "";
        this.color1 = "";
        this.color2 = "";
        this.color3 = "";
        this.color4 = "#000000";
        this.showDiv = true;
        this.showTime1 = true;
        this.showTime2 = true;
        this.showTime3 = true;
        this.showTime4 = true;
        this.type = 4;
      }
    }
  }
}
</script>

<style scoped>

</style>
